package com.v2.k4;


import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 测试事件发布
 */
@Configuration
public class Test3 {

	@Bean
	public ApplicationListener<ApplicationEvent> applicationListener() {

		return new ApplicationListener<ApplicationEvent>() {
			@Override
			public void onApplicationEvent(ApplicationEvent event) {
				System.out.println("接收到了一个事件..."+event.toString());
			}
		};

	}


	public static void main(String[] args) {

		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(Test3.class);
		applicationContext.publishEvent("kkkkk");  //输出了两个事件，一个是启动时spring的时间，一个是这次发布的事件

	}

}
